<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="施工报备单号" prop="reportNum">
        <el-input
          v-model="queryParams.reportNum"
          placeholder="请输入施工报备单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="整改时间" prop="rectificationTime">
        <el-date-picker clearable
          v-model="queryParams.rectificationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择整改时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['check:rectificationReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['check:rectificationReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['check:rectificationReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['check:rectificationReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="rectificationReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="问题整改上报id" align="center" prop="rectificationReportId" />
      <el-table-column label="施工报备单号" align="center" prop="reportNum" />
      <el-table-column label="项目名称" align="center" prop="projectName" :show-overflow-tooltip='true'/>
      <el-table-column label="检查问题单号" align="center" prop="checkProblemNum">
        <template slot-scope="scope">
          <router-link :to="'/check/checkProblem/detail/'+scope.row.checkProblemId" class="link-type">
            <span>{{ scope.row.checkProblemNum }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="整改描述" align="center" prop="rectificationRemark" :show-overflow-tooltip='true'/>
      <el-table-column label="负责人" align="center" prop="headName" />
      <el-table-column label="整改时间" align="center" prop="rectificationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rectificationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属管辖大队" align="center" prop="deptName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['check:rectificationReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['check:rectificationReport:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改整改上报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="施工报备id" prop="reportInfoId">
          <el-input v-model="form.reportInfoId" placeholder="请输入施工报备id" />
        </el-form-item>
        <el-form-item label="检查问题id" prop="checkProblemId">
          <el-input v-model="form.checkProblemId" placeholder="请输入检查问题id" />
        </el-form-item>
        <el-form-item label="整改描述" prop="rectificationRemark">
          <el-input v-model="form.rectificationRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="整改照片和视频" prop="rectificationFileId">
          <el-input v-model="form.rectificationFileId" placeholder="请输入整改照片和视频" />
        </el-form-item>
        <el-form-item label="负责人" prop="head">
          <el-input v-model="form.head" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="整改时间" prop="rectificationTime">
          <el-date-picker clearable
            v-model="form.rectificationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择整改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 查看整改上报对话框 -->
    <el-dialog :title="title" :visible.sync="viewOpen" width="500px" append-to-body>
      <el-form label-width="120px">
        <el-form-item label="施工报备单号" >
         {{form.reportNum}}
        </el-form-item>
        <el-form-item label="项目名称" >
          {{form.projectName}}
        </el-form-item>
        <el-form-item label="检查问题单号" >
          {{form.checkProblemNum}}
        </el-form-item>
        <el-form-item label="整改描述">
          {{form.rectificationRemark}}
        </el-form-item>
        <el-form-item label="整改照片和视频">
          <image-preview :value="this.rectificationFileData" fileId='rectificationFileId'/>
        </el-form-item>
        <el-form-item label="负责人" prop="head">
         {{form.headName}}
        </el-form-item>
        <el-form-item label="整改时间" prop="rectificationTime">
          {{form.rectificationTime}}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRectificationReport, getRectificationReport, delRectificationReport, addRectificationReport, updateRectificationReport } from "@/api/check/rectificationReport";

export default {
  name: "RectificationReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 整改上报表格数据
      rectificationReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportInfoId: null,
        rectificationRemark: null,
        rectificationFileId: null,
        head: null,
        rectificationTime: null,
        roadName: null,
        direction: null,
      },
      // 表单参数
      form: {},

      //  是否显示详情弹出层
      viewOpen: false,

      //整改上报附件
      rectificationFileData:[],
      // 表单校验
      rules: {
        reportInfoId: [
          { required: true, message: "施工报备id不能为空", trigger: "blur" }
        ],
        checkProblemId: [
          { required: true, message: "检查问题id不能为空", trigger: "blur" }
        ],
        rectificationRemark: [
          { required: true, message: "整改描述不能为空", trigger: "blur" }
        ],
        head: [
          { required: true, message: "负责人不能为空", trigger: "blur" }
        ],
        rectificationTime: [
          { required: true, message: "整改时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "所属大队不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询整改上报列表 */
    getList() {
      this.loading = true;
      listRectificationReport(this.queryParams).then(response => {
        this.rectificationReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rectificationReportId: null,
        reportInfoId: null,
        checkProblemId: null,
        rectificationRemark: null,
        rectificationFileId: null,
        head: null,
        rectificationTime: null,
        longitude: null,
        latitude: null,
        roadName: null,
        direction: null,
        deptId: null,
        reviewedBy: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rectificationReportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加整改上报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const rectificationReportId = row.rectificationReportId || this.ids
      getRectificationReport(rectificationReportId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改整改上报";
        this.rectificationFileData = response.data.rectificationFile;
      });
    },

    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const rectificationReportId = row.rectificationReportId || this.ids
      getRectificationReport(rectificationReportId).then(response => {
        this.form = response.data;
        this.viewOpen = true;
        this.title = "查看整改上报";
        this.rectificationFileData = response.data.rectificationFile;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.rectificationReportId != null) {
            updateRectificationReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRectificationReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rectificationReportIds = row.rectificationReportId || this.ids;
      this.$modal.confirm('是否确认删除整改上报编号为"' + rectificationReportIds + '"的数据项？').then(function() {
        return delRectificationReport(rectificationReportIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('check/rectificationReport/export', {
        ...this.queryParams
      }, `rectificationReport_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
